package com.ustcinfo.study.scala.r2.mazheng


/*
 * code by mazheng at 2018/8/4 9:00
 * a simple scala example
 * */


object test {

    def main(args:Array[String]){
      
      val sparkConf =   new sparkConf().setMaster("local").setAppName("test")
      val sc = new SparkContext(sparkConf)
      val txtEdd = sc.textFile("src/main/resources/test")
      
      /*
       * split:分割
       * map：映射
       * reduceByKey:统计 
       * */
      
      
      txtRdd
        .filter(x => x.trim().length>0)
        .map(x => x.split(" "))
        .flatMap(x => x)
        .map(x => (x,1))
        .reduceByKey(_+_)
        .map(x =>(x._2,x_1)).sortByKey(false).take(10)
        .foreach(println)
      
    
    }
}